<template>
  <a-modal
    :title="`运营商业务退货`"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="
      () => {
        $emit('ok')
      }
    "
    @cancel="
      () => {
        $emit('cancel')
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-alert
          message=""
          description="【运营商业务】会列出最近一周的销售，如果没有列出，请在【业务编号】中输入要退货的业务编号。以下两个二选一，优先使用【运营商业务】"
          type="warning"
        />
        <a-form-item label="运营商业务" style="margin-top: 20px">
          <a-select v-decorator="['goodName']" placeholder="请选择" name="goodName" >
            <a-select-option :value="i.id" v-for="i in this.option1" :key="i.value">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="业务编号">
          <a-input v-decorator="['opBusinessId']" placeholder="请输入业务编号" name="opBusinessId" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
<script>
import pick from 'lodash.pick'
import { getOpBusinessListUsingPOST1 } from '@/api/api/qiantaizhangwu.ts'
// 表单字段
const fields = ['goodName', 'opBusinessId','id']

export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
  },
  data() {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 },
      },
    }
    return {
      sp: true,
      yys: true,
      AA: true,
      queryParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
      option1:[],
      form: this.$form.createForm(this),
    }
  },
  created() {
    this.handle1()
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
  methods:{
    handle1() {
      getOpBusinessListUsingPOST1(this.queryParam)
        .then((res) => {
          this.option1 = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
  }
}
</script>